﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TekaMUD.Engine.Framework
{
	public class Randomizer
	{
		private static Random _random;

		static Randomizer()
		{
			_random = new Random();
		}

		public static int GetInteger(int minBound, int maxExclusiveBound)
		{
			return _random.Next(minBound, maxExclusiveBound);
		}

		public static double GetDouble()
		{
			return _random.NextDouble();
		}

		/// <summary>
		/// Selects a random entry of a table of cumulative probabilities
		/// </summary>
		/// <returns>An index of that table</returns>
		public static int PickRandomEntry(double[] table)
		{
			double acc, n;
			int i;

			n = GetDouble();
			acc = 0;

			for (i = 0; i < table.Length; i++)
			{
				if (n <= (acc += table[i]))
					return i;
			}

			return 0;
		}
	}
}